Economic activities in Zürich

Zürich Statistical Office collects data on the city and its residents. This data is published as Linked Data.

In this tutorial, we will show how to work with Linked Data. Mainly, we will see how to work with data on economic activities.
We will look into how to query, process, and visualize it.

1. Restaurants over time
2. Restaurants in city quartiers
3. After-school care: gender-representation

SPARQL endpoint

Data on some economic activities is published as Linked Data. It can be accessed with SPARQL queries.
You can send queries using HTTP requests. The API endpoint is https://ld.stadt-zuerich.ch/query/.

Let's use SparqlClient from graphly to communicate with the database. Graphly will allow us to:

SPARQL queries can become very long. To improve the readibility, we will work wih prefixes.

Using add_prefixes method, we can define persistent prefixes. Every time you send a query, graphly will now automatically add the prefixes for you.

Restaurants over time

Let's find the number of restaurants in Zurich over time. This information is available in the AST-BTA data cube. To give restaurant numbers a context, let's scale them by population size. The number of inhabitants over time can be found in the BEW data cube.

The query for number of inhabitants and restaurants over time is as follows:

Let's calculate number of restaurants per 10 000 inhabitants

Restaurants in city quartiers

Let's find the number of restaurants in different parts of the city. The data on restaurants is available in the AST-BTA data cube. To show the quartiers on a map, we will need their geographic coordinates. This data is available in Wikidata. We will get the number of restaurants per district from our endpoint, and the quartier centroid from Wikidata.

Both information can be obtained using a SPARQL federated query. The endpoint for Wikidata is <https://query.wikidata.org/sparql>.

The query for quartiers, its centroids, and number of restaurants is:

Let's classify the number of restaurants into 5 different buckets. We can use the mapclassify library to assign values in the restaurant column into one of five categories.

Classified values can be easily visualized on the map.

After-school care: gender-representation

Let's take a look at gender representation in the public sector. In the BES-BTA-SEX data cube we can find information on the number of employees in different organizations. The data is reported separately for each sex, and various establishment types. Let's find the number of male and female employees in after-school care (Hort).

The query for the number of female and male employees in after-school care over time looks as follows:

Let's rearrange and rename the columns: